<template>
  <div id="app">
    <el-container>
      <el-header>
        <div class="header">
          <img alt="" src="../assets/img/2.jpg">
          <span>商品管理系统</span>
        </div>
        <el-button plain round type="primary" @click="logOut">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px':'200px'">
          <div class="el-aside-show" @click="toggleCollapse">|||</div>
          <!--侧边栏菜单区-->
          <el-menu :collapse="isCollapse" active-text-color="black" background-color=" #2b85e4" collapse-transition
                   router text-color="white" unique-opened>
            <!--一级菜单-->
            <el-submenu v-for="(item,index) in menuList" :key="item.id" :index="item.id.toString()">
              <template #title>
                <i :class="iconList[index]" class="iconImg"></i>
                <span>{{ item.authName }}</span>
              </template>
              <!--二级菜单-->
              <el-menu-item v-for="subItem in item.children" :key="subItem.id" :index="'/home/'+subItem.path">
                <i class="el-icon-menu"></i>
                <template #title>{{ subItem.authName }}</template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
            <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {request} from "../network/axios";
import {ElMessage} from "element-plus";

export default {
  name: "Home",
  created() {
    this.getMenuList()
  },
  data() {
    return {
      menuList: [],
      iconList: ['el-icon-s-custom', 'el-icon-unlock', 'el-icon-s-goods', 'el-icon-tickets', 'el-icon-coin'],
      isCollapse: false
    }
  },
  methods: {
    //退出导航
    logOut() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    //获取左侧列表信息
    getMenuList() {
      request({
        url: '/menus'
      }).then(res => {
        if (res.status !== 200) ElMessage.error("获取信息失败")
        console.log(res);
        this.menuList = res.data.data
      })

    },
    //左侧栏的合并转换
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    }
  },

}
</script>

<style scoped src="../assets/css/Home.css">

</style>